Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

219
Visualizações
socket.io | are asynchronous responses stacked up in order?
  1. Client emits newdataFromClient to sever

  2. server starts processing new data:

socket.on('newdataFromClient', async(newdataFromClient) => {
  let result = await doSomething(newdataFromClient)
  socket.emit('response', result)
})
  1. while server is not done processing, client sends more data

Server will eventually emit 2 results and send them back to the client. One for each newdataFromClient it received.

Will the results be sent back in order or is whichever one finishes faster the one that will be sent back first ?

I'm running a basic node server on a Macbook Pro. If the server starts getting multiple newdataFromClient one after another, will it start handling each on separate threads and when it runs out of threads it will start stacking them up in order?

I assume that my server will crash anyway if it can't handle too many calls but that's a separate issue.

Here I'm only interested in the order of the server responses.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

socket.io events will arrive in the order they were sent from the server. The underlying transport here is TCP which keeps packets in order.

Now, if the server itself is handling the individual arriving requests and in its processing to send a result, it has asynchronous operations, there may be no guarantee on the server for what order it will send the responses. In fact, it is likely that the completion order on the server is unpredictable.

Will the results be sent back in order or is whichever one finishes faster the one that will be sent back first ?

Whichever one finishes first on the server and sends a message back is the one that will be received first in the client. These are independent messages that simply go on the transport en-route to the client whenever they are emitted at the server. And the TCP transport which underlies the webSocket protocol which underlies the socket.io engine will keep these packets in the order they were originally sent from the server.


Ack feature in socket.io

socket.io does have a means of getting a specific "ack" back from a specific message. If you look at the socket.emit() doc, you will see that one of the optional arguments is an ack callback. That can be used (in conjunction with the server sending an ack response) to get a specific response to this specific message. For the details on how to implement, see both the client and server-side doc for that "ack" feature.

Absent using that built-in feature, you would have to build your own messageID based system so you can match a given response coming back from the server to the original request (that's what the "ack" feature does internally) because socket.io is not natively a request/response protocol (it's a message protocol).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda